package com.blt.govdata.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.blt.govdata.controller.base.BaseController;
import com.blt.govdata.model.TProjectApproveBefore;
import com.blt.govdata.service.ITProjectApproveBeforeService;
import com.google.common.collect.ImmutableMap;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yangjianguo
 * @since 2018-04-04
 */
@RestController
@RequestMapping("/tProjectApproveBefore")
public class TProjectApproveBeforeController extends BaseController {

    @Autowired
    ITProjectApproveBeforeService service;

    /**
     * 通过项目ID查询
     * */
    @RequestMapping(value = "selectByPid",params = {"pId"})
    public Map<String,Object> selectByPid(Integer pId){
        return ImmutableMap.of("status","true","data",this.service.selectList(BeanUtils.instantiate(EntityWrapper.class).where("p_id = {0}",pId)));
    }


    /**
     * 新增
     * */
    @RequestMapping(value = "addBefore",params = {"pId"})
    public Map<String,Object> addBefore(TProjectApproveBefore before){
        boolean result = this.service.insert(before);
        return ImmutableMap.of("status","true","data",result);
    }


    /**
     * 修改
     * */
    @RequestMapping(value = "editBefore",params = {"id"})
    public Map<String,Object> editBefore(TProjectApproveBefore before){
        boolean result = this.service.updateById(before);
        return ImmutableMap.of("status","true","data",result);
    }

    /**
     * 新增或修改
     * */
    @RequestMapping(value = "createOrModifyBefore",params = {"pId"})
    public Map<String,Object> createOrModifyBefore(TProjectApproveBefore before){
        TProjectApproveBefore one = this.service.selectOne(BeanUtils.instantiate(EntityWrapper.class).where("p_id = {0}",before.getpId()));
        if(null == one){
            return addBefore(before);
        }
        return editBefore(before);
    }

}

